<template>
  <div class="app-container">
    <h2 class="text-center">{{ paperData.title}}</h2>
    <p class="text-center" style="color: #666">{{ paperData.createTime }}</p>

    <div style="width: 100%;display: flex; justify-content: end; opacity: 0.6;">
      <el-button type="primary" @click="()=>this.$router.push({name:'SafetyExam'})" >进入下一场</el-button>
    </div>

    <el-row :gutter="24" style="margin-top: 50px">
      <el-col :span="8" class="text-center">
        考生姓名：{{ paperData.realName }} ({{ paperData.userName }})
      </el-col>

      <el-col :span="8" class="text-center">
        考试用时：{{ paperData.userTime }}分钟
      </el-col>

      <el-col :span="8" class="text-center">
        考试得分：{{ paperData.userScore }}
      </el-col>
    </el-row>

    <el-card style="margin-top: 20px">
      <div class="qu-content" v-for="(item,index) in paperData.popQuList" :key="index">
        <p>题目{{ index + 1 }}.（得分：{{ item.actualScore }}）</p>
        <div class="qu">
          <img :src="quList[index].image" alt="">
        </div>
        <div>
          <el-row :gutter="24">
            <el-col :span="12" style="color: #24da70">
              正确答案：{{ quList[index].name }}
            </el-col>

            <el-col
              v-if="!item.answered"
              :span="12"
              style="text-align: right; color: #ff0000"
            >
              答题结果：未答
            </el-col>

            <el-col
              v-if="item.answered && !item.isRight"
              :span="12"
              style="text-align: right; color: #ff0000"
            >
              答题结果：{{ quList[index].quPopAnswer.name }}
            </el-col>

            <el-col
              v-if="item.answered && item.isRight"
              :span="12"
              style="text-align: right; color: #24da70"
            >
              答题结果：{{ quList[index].quPopAnswer.name }}
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { paperPopResult } from "@/api/paper/exam";
import Markdown from "vue-meditor";

export default {
  name: "AuctionGoodsDetail",
  components: { Markdown },
  data() {
    return {
      // 试卷ID
      paperId: "",
      paperData: {
        popQuList:[],
        popQu:[]
      },
      popQuList:[],
      quList:[]
    };
  },
  created() {
    const id = this.$route.params.id;
    if (typeof id !== "undefined") {
      this.paperId = id;
      this.fetchData(id);
    }
  },
  methods: {
    fetchData(id) {
      const params = { id: id };
      paperPopResult(params).then((response) => {
        // 试卷内容
        this.paperData = response.data;
        // this.popQuList = response.data.popQuList
        console.log(response.data);

        // 填充该题目的答案
       this.paperData.popQu.forEach(item=>{
          this.quList.push(item)
       })

      });
    },
  },
};
</script>

<style scoped>
.qu-content {
  border-bottom: #eee 1px solid;
  padding-bottom: 10px;
}

.qu-content div {
  line-height: 30px;
}

.qu {
  margin-bottom: 20px;
}

.qu img{
  width: 200px;
  height: 200px;
}

.el-checkbox-group label,
.el-radio-group label {
  width: 100%;
}

.card-title {
  background: #eee;
  line-height: 35px;
  text-align: center;
  font-size: 14px;
}

.card-line {
  padding-left: 10px;
}

.card-line span {
  cursor: pointer;
  margin: 2px;
}
</style>
